package com.xuegao.xuegaololskills.swing;

import javax.swing.*;
import java.awt.*;

/**
 * <br/> @PackageName：com.xuegao.xuegaololskills.swing
 * <br/> @ClassName：ShowCenter
 * <br/> @Description：
 * <br/> @author：xuegao
 * <br/> @date：2020/11/13 19:47
 */
public class ShowCenter extends JFrame {
    public static void main(String[] args) {
        final ShowCenter showCenter = new ShowCenter();
        SwingUtilities.invokeLater(new Runnable() {
            @Override
            public void run() {
                showCenter.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                showCenter.setSize(300, 100);
                showCenter.setAlwaysOnTop(true);
                //The following code ensure the window shown on the center of screen.
                Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
                showCenter.setLocation((dim.width - showCenter.getWidth()) / 2, (dim.height - showCenter.getHeight()) / 2);

                showCenter.setVisible(true);
            }
        });
    }
}
